var Project = {
    tableId: "projectTable"
};
var numberPage = 1;
layui.use(['table', 'admin', 'ax', 'form', 'layer', 'jquery'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var form = layui.form;
    var layer = layui.layer;

    /**
     * 检索区域
     */
    var qyAjax = new $ax("/project/getAreaByType");
    qyAjax.set("type", 2);
    var qyResult = qyAjax.start();
    $.each(qyResult, function (index, data) {
        $("#provinceId").append("<option value='" + data.id + "'>" + data.simpleName + "</option>");
    });
    form.render();

    /**
     * 初始化表格的列
     */
    Project.initColumn = function () {
        return [[
            // {type: 'checkbox'},
            {type: 'numbers', title: '序号', align: "center",width: 46},
            {field: 'provinceName', title: '门店名称(分店名称)', align: "center", width: 200},
            {field: 'cityName', title: '门店地址', align: "center", width: 200},
            {field: '',  title: '对外门店名称(品牌)', align: "center", width: 120,templet:function (d) {
                return '半天妖';
                }},
            {field: '',  title: '公司归属', align: "center", width: 250,edit:'text',templet:function (d) {
                    return '济南半天妖餐饮有限公司';
                }},
            {field: 'yaoma',  title: '<div>门店(前厅/客服)<br/>电话订餐电话</div>', align: "center", width: 150,edit:'text'},
            {field: 'yaoma',  title: '门店营业时间', align: "center", width: 150,edit:'text'},
            {field: 'yaoma',  title: '法人', align: "center", width: 150,edit:'text'},
            {field: 'yaoma',  title: '银行卡开户人', align: "center", width: 150,edit:'text'},
            {field: 'yaoma',  title: '银行卡卡号', align: "center", width: 150,edit:'text'},
            {field: 'yaoma',  title: '审核状态', align: "center", width: 150,edit:'text'},
            {field: 'yaoma',  title: '操作', align: "center", width: 150,edit:'text'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    Project.search = function () {
        var queryData = {};
        queryData['provinceId'] = $("#provinceId").val();
        queryData['cityId'] = $("#cityId").val();
        queryData['name'] = $("#name").val();
        queryData['yaoma'] = $("#yaoma").val();
        Project.tableCfg.where=queryData;
        table.render(Project.tableCfg);
    };


    /**
     * 导出excel按钮
     */
    Project.exportExcel = function () {
       /* if(todayval){
            p='kyDate='+Project.getDate();
        }else{
            var  para = sessionStorage.getItem("jindu");
            if(para!=null){
                var o=JSON.parse(para);
                p='provinceId='+o.provinceId+'&year='+o.year+'&yyjl='+o.yyjl+'&dd='+o.dd+'&status='+o.status;
            }
        }*/
        window.location.href=Feng.ctxPath + '/project/yaomaListExport?';
    };

    /**
     * 渲染表格
     */
    Project.tableCfg={
        elem: '#' + Project.tableId,
        page: true,
        url:Feng.ctxPath + '/project/yaomaList',
        cellMinWidth: 100,
        even: true,
        cols: Project.initColumn(),
    };
    table.render(Project.tableCfg);
    /**
     * 搜索按钮点击事件
     */
    $('#btnSearch').click(function () {
        Project.search();
    });

    /**
     * 导出excel
     */
    $('#export').click(function () {
        Project.exportExcel();
    });

    /**
     * 工具条点击事件
     */
    /*table.on('tool(' + Project.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        $("#ida").val(data.id);
        if (layEvent === 'manager') {
            Project.zhiDing("营运经理", "0", "40");
        }
    });*/

    form.on('select(provinceId)', function (data) {
        var provinceId = data.value;
        if (provinceId == "") {
            $("#cityId").html("");
            $("#cityId").append("<option value=''>全部</option>");
            form.render('select');
        } else {
            var qyAjax = new $ax("/area/getAreaByPid");
            qyAjax.set("pid", provinceId);
            var qyResult = qyAjax.start();
            $("#cityId").html("");
            $("#cityId").append("<option value=''>全部</option>");
            $.each(qyResult, function (index, data) {
                $("#cityId").append("<option value='" + data.id + "'>" + data.simpleName + "</option>");
            });
            form.render('select');
        }
    });


    table.on('edit('+Project.tableId+')',function(obj){
        var v = obj.value; //得到修改后的值
        var field=obj.field; //当前编辑的字段名
        var gc=obj.data; //所在行的所有相关数据
        if("yaoma"==field){
            gc.yaoma=v;
        }
        var ajax = new $ax(Feng.ctxPath + "/project/editItem", function (data) {
            if(data.success){
                Feng.success("修改成功！");
            }else{
                Feng.error(data.message);
                table.reload(Project.tableId,{page: {curr:$(".layui-laypage-em").next().html()}});
                return;
            }
        }, function (data) {
            Feng.error("修改失败！" + data.responseJSON.message)
        });
        ajax.set("id",gc.id);
        ajax.set("yaoma",v);
        ajax.start();
    });

});
